<template>
  <div class="dev">
    <el-form ref="myform" label-width="100px" label-position="right">
      <el-row>
        <el-col :span="2">
          <el-select v-model="qryType" @change="qryTypeChange">
            <el-option
              v-for="(item, index) in searchTypeOptions"
              :key="index"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="3" style="padding-left: 10px" v-show="qryType != 4">
          <el-input
            v-model="qryValue"
            clearable
            placeholder="请输入关键字"
          ></el-input>
        </el-col>
        <el-col :span="3" style="padding-left: 10px" v-show="qryType == 4">
          <el-select v-model="qryValue">
            <el-option label="需求单" value="50030002"></el-option>
            <el-option label="订单" value="50030003"></el-option>
          </el-select>
        </el-col>
        <el-col :span="1" style="padding-left: 0.1rem">
          <el-button type="primary" @click="eventDoSearch">查询</el-button>
        </el-col>
        <el-col :span="2">
          <div
              class="left ne-operation"
              style="margin-left: 0.1rem"
              @click="showHandler"
          >
            <a id="moreMes" class="ne-tab-toggle" :class="{ hover: ishow }">{{
                ishow ? "收起条件" : "更多条件"
              }}</a>
          </div>
        </el-col>
        <el-col :span="4">
                    <el-radio-group v-model="showTypeName">
                        <el-radio label="TableCard">列表展示</el-radio>
                        <el-radio label="un-order-list">卡片展示</el-radio>
                    </el-radio-group>
        </el-col>
        <el-col :span="11" style="padding-left: 50px">
          <span v-if="ceilOrderType == 'JTALL' || ceilOrderType == 'DGZ'"
            >.</span
          >
          <!-- 所有订单和我的关注不显示单选按钮筛选项 -->
<!--          <el-radio-group-->
<!--            v-model="stage"-->
<!--            v-if="ceilOrderType != 'JTALL' && ceilOrderType != 'DGZ'"-->
<!--            @change="warnChange"-->
<!--          >-->
<!--            <el-radio-->
<!--              v-for="option in ceilOrderType == 'WARN'-->
<!--                ? warnOptions-->
<!--                : stageOptions"-->
<!--              :key="option.value"-->
<!--              :label="option.value"-->
<!--              >{{ option.name }}</el-radio-->
<!--            >-->
<!--          </el-radio-group>-->
        </el-col>
        <el-col :span="5" class="right">
          <el-button-group>
            <el-popover
              height="300px"
              @show="dealShowEvent(1)"
              popper-class="ne-pending"
              placement="left"
              trigger="click"
            >
              <ul v-if="operateWithData" class="ne-pending-items">
                <li v-for="(item, index) in operateWithData" :key="index">
                  <a @click="openTopPendDialog(item, 'OPER')">{{
                    item.title
                  }}</a>
                </li>
              </ul>
              <p v-else>暂无任务</p>
              <el-button
                type="primary"
                slot="reference"
                style="
                  border-top-right-radius: 0;
                  border-bottom-right-radius: 0;
                "
              >
                操作
                <i class="el-icon-coordinate el-icon--right"></i>
              </el-button>
            </el-popover>
            <el-popover
              @show="dealShowEvent(2)"
              popper-class="ne-pending"
              placement="left"
              trigger="click"
            >
              <ul v-if="dealWithData" class="ne-pending-items">
                <li v-for="(item, index) in dealWithData" :key="index">
                  <a @click="openTopPendDialog(item, 'DEAL')">{{
                    item.title
                  }}</a>
                </li>
              </ul>
              <p v-else>暂无任务</p>
              <el-button
                type="primary"
                slot="reference"
                style="border-radius: 0"
              >
                处理
                <i class="el-icon-coordinate el-icon--right"></i>
              </el-button>
            </el-popover>
            <el-popover
              @show="dealShowEvent(3)"
              popper-class="ne-pending"
              placement="left"
              trigger="click"
            >
              <ul v-if="outputWithData" class="ne-pending-items">
                <li v-for="(item, index) in outputWithData" :key="index">
                  <a @click="openTopPendDialog(item, 'EXPORT')">{{
                    item.title
                  }}</a>
                </li>
              </ul>
              <p v-else>暂无任务</p>
              <el-button
                type="primary"
                slot="reference"
                style="border-top-left-radius: 0; border-bottom-left-radius: 0"
              >
                输出
                <i class="el-icon-coordinate el-icon--right"></i>
              </el-button>
            </el-popover>
          </el-button-group>
        </el-col>
      </el-row>
      <el-row
        class="ne-tg-ipt"
        v-show="ishow"
        style="margin-top: 0.15rem; padding: 0 0.1rem"
      >
        <el-col :span="6">
          <el-form-item label="需求单审核日期">
            <el-date-picker
              v-model="REQ_AUD_DATE"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="订单审核日期">
            <el-date-picker
              v-model="ORDER_AUD_DATE"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="竣工日期">
            <el-date-picker
              v-model="FINISH_TIME"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="填报竣工日期">
            <el-date-picker
              v-model="FINISH_OPER_DATE"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="起租日期">
            <el-date-picker
              v-model="BEGIN_RENT_TIME"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="受理日期">
            <el-date-picker
              v-model="HANDLE_TIME"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="流水号">
            <input-down v-model="CUST_SO_NUMBER">
              <side-select v-model="CUST_SO_NUMBER_TYPE"></side-select>
            </input-down>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户编码">
            <input-down v-model="CUST_NUMBER">
              <side-select v-model="CUST_NUMBER_TYPE"></side-select>
            </input-down>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="电路代号/设备号">
            <input-down v-model="ACC_NBR">
              <side-select v-model="ACC_NBR_TYPE"></side-select>
            </input-down>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户名称">
            <input-down v-model="CUST_NAME">
              <side-select v-model="CUST_NAME_TYPE"></side-select>
            </input-down>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-dialog
      class="ne-pending-task"
      append-to-body
      :width="isContent.width"
      :top="isContent.top"
      :title="isContent.title"
      v-if="pendItemVisible"
      :visible.sync="pendItemVisible"
    >
      <component
        @close="fun"
        :show.sync="pendItemVisible"
        :is="isContent.content"
        :ODKInfo="isContent.ODKInfo"
        :CTOInfo="isContent.CTOInfo"
      ></component>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import InputDown from "../public/forms/InputDown/index";
import SideSelect from "../public/forms/InputDown/SideSelect.vue";
import DicCustomerDrawer from "@/components/customer/form/DicCustomerDrawer";
import CustOrderService from "@/api/order/CustOrderService";
import OrderManager from "@/components/custorder/pengding/OrderManager";
import DeletePage from "@/components/custorder/DeletePage";
import priceApply from "@/components/custorder/priceApply";
import { constant } from "@/utils/constant";
import { mapState } from "vuex";
import OrderFiles from "@/components/custorder/OrderFiles";
import OrderService from "@/api/order/OrderService.js";
import UploadIdeaFiles from "@/components/custorder/examine/UploadIdeaFiles";
export default {
  props: {
    selectedCustomerInfo: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      xqValue: '',
      ishow: false, //更多条件隐藏
      operatingList: [
        { id: 1, name: "任务1" },
        { id: 2, name: "任务2" },
        { id: 3, name: "任务3" },
      ],
      dealwithList: [
        { id: 1, name: "任务1" },
        { id: 2, name: "任务2" },
        { id: 3, name: "任务3" },
      ],
      outputList: [
        { id: 1, name: "任务1" },
        { id: 2, name: "任务2" },
        { id: 3, name: "任务3" },
      ],
      operateWithData: [],
      dealWithData: [],
      outputWithData: [],
      isContent: "",
      pendItemVisible: "",
      //调用规则平台返回值
      callRuleRtnCode: 0,
    };
  },
  components: {
    InputDown,
    SideSelect,
    DicCustomerDrawer,
    OrderManager,
    DeletePage,
    priceApply,
    OrderFiles,
    UploadIdeaFiles
  },
  computed: {
    ...mapState("orders", [
      "orderType",
      "qryType",
      "qryValue",
      "orderStage",
      "stage",
      "showTypeName",
      "datasource"    
      ]),
    ...mapState("user", ["user"]),
    ...mapGetters([
      "conditions",
      "searchTypeOptions",
      "stageOptions",
      "warnOptions",
      "ceilOrderType",
    ]),
    qryType: {
      get() {

        return this.$store.state.orders.qryType || 1;
      },
      set(value) {
        this.$store.commit("orders/SET_QRYTYPE", value);
      },
    },
    qryValue: {
      get() {
        return this.$store.state.orders.qryValue;
      },
      set(value) {
        this.$store.commit("orders/SET_QRYVALUE", value);
      },
    },
    stage: {
      get() {
        return this.$store.state.orders.stage;
      },
      set(value) {
        this.$store.commit("orders/SET_STAGE", value);
      },
    },
    showTypeName: {
      get() {
        return this.$store.state.orders.showTypeName;
      },
      set(value) {
        this.$store.commit("orders/SET_SHOW_TYPE_NAME", value);
      },
    },
    // 需求单审核日期
    REQ_AUD_DATE: {
      get() {
        return [
          this.$store.state.orders.B_REQ_AUD_DATE,
          this.$store.state.orders.E_REQ_AUD_DATE,
        ];
      },
      set(value) {
        if(value==null){
          this.$store.commit("orders/SET_B_REQ_AUD_DATE", '');
          this.$store.commit("orders/SET_E_REQ_AUD_DATE", '');
        }else{
          this.$store.commit("orders/SET_B_REQ_AUD_DATE", value[0]);
          this.$store.commit("orders/SET_E_REQ_AUD_DATE", value[1]);
        }
      },
    },

    // 订单审核日期
    ORDER_AUD_DATE: {
      get() {
        console.log([
          this.$store.state.orders.B_ORDER_AUD_DATE,
          this.$store.state.orders.E_ORDER_AUD_DATE,
        ]);
        return [
          this.$store.state.orders.B_ORDER_AUD_DATE,
          this.$store.state.orders.E_ORDER_AUD_DATE,
        ];
      },
      set(value) {

        if(value==null){
          this.$store.commit("orders/SET_B_ORDER_AUD_DATE", '');
          this.$store.commit("orders/SET_E_ORDER_AUD_DATE", '');
        }else {


          this.$store.commit("orders/SET_B_ORDER_AUD_DATE", value[0]);
          this.$store.commit("orders/SET_E_ORDER_AUD_DATE", value[1]);
        }
      },
    },

    // 竣工日期
    FINISH_TIME: {
      get() {
        return [
          this.$store.state.orders.B_FINISH_TIME,
          this.$store.state.orders.E_FINISH_TIME,
        ];
      },
      set(value) {
        if(value == null){
          this.$store.commit("orders/SET_B_FINISH_TIME", '');
          this.$store.commit("orders/SET_E_FINISH_TIME", '');
        }else{
          this.$store.commit("orders/SET_B_FINISH_TIME", value[0]);
          this.$store.commit("orders/SET_E_FINISH_TIME", value[1]);
        }
      },
    },

    // 填报竣工日期
    FINISH_OPER_DATE: {
      get() {
        return [
          this.$store.state.orders.B_FINISH_OPER_DATE,
          this.$store.state.orders.E_FINISH_OPER_DATE,
        ];
      },
      set(value) {
        if(value == null){
          this.$store.commit("orders/SET_B_FINISH_OPER_DATE", '');
          this.$store.commit("orders/SET_E_FINISH_OPER_DATE", '');
        }else{
          this.$store.commit("orders/SET_B_FINISH_OPER_DATE", value[0]);
          this.$store.commit("orders/SET_E_FINISH_OPER_DATE", value[1]);
        }
      },
    },

    // 起租日期
    BEGIN_RENT_TIME: {
      get() {
        return [
          this.$store.state.orders.B_BEGIN_RENT_TIME,
          this.$store.state.orders.E_BEGIN_RENT_TIME,
        ];
      },
      set(value) {
        if(value == null){
          this.$store.commit("orders/SET_B_BEGIN_RENT_TIME", '');
          this.$store.commit("orders/SET_E_BEGIN_RENT_TIME", '');
        }else{
          this.$store.commit("orders/SET_B_BEGIN_RENT_TIME", value[0]);
          this.$store.commit("orders/SET_E_BEGIN_RENT_TIME", value[1]);
        }
      },
    },

    // 受理日期
    HANDLE_TIME: {
      get() {
        return [
          this.$store.state.orders.B_HANDLE_TIME,
          this.$store.state.orders.E_HANDLE_TIME,
        ];
      },
      set(value) {
        if(value==null){
          this.$store.commit("orders/SET_B_HANDLE_TIME", '');
          this.$store.commit("orders/SET_E_HANDLE_TIME", '');
        }else{
          this.$store.commit("orders/SET_B_HANDLE_TIME", value[0]);
          this.$store.commit("orders/SET_E_HANDLE_TIME", value[1]);
        }
      },
    },

    // 流水号
    CUST_SO_NUMBER: {
      get() {
        return this.$store.state.orders.CUST_SO_NUMBER;
      },
      set(value) {
        this.$store.commit("orders/SET_CUST_SO_NUMBER", value);
      },
    },
    // 流水号查询类型：1精确查询 2模糊查询
    CUST_SO_NUMBER_TYPE: {
      get() {
        return this.$store.state.orders.CUST_SO_NUMBER_TYPE;
      },
      set(value) {
        this.$store.commit("orders/SET_CUST_SO_NUMBER_TYPE", value);
      },
    },
    // 客户编码
    CUST_NUMBER: {
      get() {
        return this.$store.state.orders.CUST_NUMBER;
      },
      set(value) {
        this.$store.commit("orders/SET_CUST_NUMBER", value);
      },
    },
    //客户编码查询类型： 1精确查询 2模糊查询
    CUST_NUMBER_TYPE: {
      get() {
        return this.$store.state.orders.CUST_NUMBER_TYPE;
      },
      set(value) {
        this.$store.commit("orders/SET_CUST_NUMBER_TYPE", value);
      },
    },
    // 电路代号/设备号
    ACC_NBR: {
      get() {
        return this.$store.state.orders.ACC_NBR;
      },
      set(value) {
        this.$store.commit("orders/SET_ACC_NBR", value);
      },
    },
    // 电路代号/设备号查询类型： 1精确查询 2模糊查询
    ACC_NBR_TYPE: {
      get() {
        return this.$store.state.orders.ACC_NBR_TYPE;
      },
      set(value) {
        this.$store.commit("orders/SET_ACC_NBR_TYPE", value);
      },
    },
    // 客户名称
    CUST_NAME: {
      get() {
        return this.$store.state.orders.CUST_NAME;
      },
      set(value) {
        this.$store.commit("orders/SET_CUST_NAME", value);
      },
    },
    // 客户名称：1精确查询 2模糊查询
    CUST_NAME_TYPE: {
      get() {
        return this.$store.state.orders.CUST_NAME_TYPE;
      },
      set(value) {
        this.$store.commit("orders/SET_CUST_NAME_TYPE", value);
      },
    },
  },
  methods: {
    ...mapActions("orders", ["qryPendingOrderList"]),
    fun() {
      this.pendItemVisible = false;
      this.eventDoSearch();
    },
    isSendFlag: function (objActionData) {
      var flag = false;
      objActionData.meta.forEache((obj) => {
        if (
          ("0" == obj.sendFlag && "0" == obj.audResultFlag) ||
          "2" == obj.AUD_RESULT_FLAG
        ) {
          flag = true;
        } else {
          flag = false;
        }
      });
      return flag;
    },
    /**
     * 控制展开/收缩按钮
     */
    showHandler() {
      this.ishow = !this.ishow;
    },
    //浮动菜单具体项目点击事件
    openTopPendDialog(item, paramType) {



      this.isContent = item;
      this.dealOperation(paramType);
    },
    //top按钮的判断
    dealOperation: function (paramType) {
      var selectList = this.isContent.CTOInfo;
      this.orderDeal(paramType);
    },
    //调用规则平台通用方法 lb
    async callRule(ruleParam) {
      //默认为2
      this.callRuleRtnCode = 3;
      const result = await OrderService.rulePlatfromCheck(ruleParam);
      let ruleCode = result.code;
      let ruleMsg = result.msg;
      //直接通过校验
      if (ruleCode != 0) {
        //校验结果有警告或者拒绝，弹窗提示
        //图标样式
        let iconType = "warning";
        if (ruleCode == 2) {
          iconType = "error";
        }
        await this.$confirm(ruleMsg, "提示", {
          confirmButtonText: "确定",
          type: iconType,
        })
          .then(() => {})
          .catch(() => {});
      }
      this.callRuleRtnCode = ruleCode;
    },


    //每条浮动菜单的具体执行操作
    async orderDeal(paramType) {
      //
      var funcCode = this.isContent.ODKInfo.FUNC_CODE;
      var selectedCustomer = localStorage.getItem("radionSelectedcustormer");
      var custormer = JSON.parse(selectedCustomer);

      this.isContent.CTOInfo = [custormer];
      var Constant = constant();
      var SelRows = custormer;

      //输出订单列表
      if (funcCode == "EXPORT_ORDER_LIST"){
        console.log("os",this.datasource)
          //输出订单列表
          let customerOrderList = this.datasource.customerOrder;
            let param = [];
            for (var i = 0; i < customerOrderList.length; i++) {
               var o = customerOrderList[i];
                console.log("o",o)
                var paramObj = new Object();
                paramObj.CUST_SO_NUMBER = o['custSoNumber'];        
                paramObj.CUST_NUMBER = o['custNumber'];          
                paramObj.CUST_NAME = o['custName'];            
                paramObj.CUST_SIGN = o['batchNbr'];                  
                paramObj.TYPENAME = o['custOrderTypeName'];       
                paramObj.AUD_STATE = o['audState'];          
                paramObj.STATENAME = o['statusCdName'];                
                paramObj.ACCEPT_TIME = o['acceptTime'];          
                paramObj.AUD_DATE = o['audDate'];      
                paramObj.CUST_MANAGER_NAME = o['custManagerName'];              
                paramObj.CUST_MANAGER_PHONE = o['custManagerPhone'];
                paramObj.BUSI_MANAGER_NAME = o['audFirstName'];           
                paramObj.BUSI_MANAGER_PHONE = o['audFirstPhone'];                    
                paramObj.PARTNER_NAME = o['orderSourceName'];        
                paramObj.PROJECT_NO = o['projectId'];         
                paramObj.PROJECT_NAME = o['projectName'];            
                // paramObj.PFLAG = o[''];    //这个字段不要了      
                paramObj.STAFF_NAME = o['staffName'];            
                paramObj.ORG_NAME = o['orgName'];                      

                param.push(paramObj);
            }
            this.exportExcelOrderList(param);
            return;
      }

      if (custormer == null || custormer["custSoNumber"] == null) {
        this.$message({
          type: "warn",
          message: "请选择一条数据!",
        });
        return;
      }

      //校验工单操作处理规则埋点
      //查询是否送审核
      // select SEND_FLAG,AUD_RESULT_FLAG from order_item_audit where cust_so_number =#{custSoNumber} and batch_nbr =#{batchNbr} and CUST_ID = #{custId}
      let params = {
        interFaceType: "ORDER",
        sqlId: "2021072301",
        paramStr: "custSoNumber:"+SelRows.custSoNumber+";batchNbr:"+SelRows.batchNbr+";custId:"+SelRows.custId
      };
      const result = await OrderService.executeSql(params);
      let orderSendAuditRes = result.meta.resList.executeSqlResps;
      let SEND_FLAG = orderSendAuditRes[0].SEND_FLAG;
      let AUD_RESULT_FLAG = orderSendAuditRes[0].AUD_RESULT_FLAG;
      //默认已经送审核
      let sendFlag=1;
      if (("0" == SEND_FLAG && "0" == AUD_RESULT_FLAG) || ("2" == AUD_RESULT_FLAG) ) {
        //未送审
        sendFlag = 0;
      }
      var ruleParam = [
        {
          PUB_REQ: {
            TYPE: "GOVCRM.TASK.dealCheck",
          },
          CUST_ORDER_DEAL: {
            CUST_SO_NUMBER: SelRows.custSoNumber + "",
            BATCH_NBR: SelRows.batchNbr + "",
            CUST_ORDER_TYPE: SelRows.custOrderType + "",
            SUB_CODE: paramType + "",
            DEAL_CODE: funcCode + "",
            CUST_ID: SelRows.custId + "",
            STAFF_ID: this.user.staffId + "",
            ORG_ID: this.user.orgId + "",
            SEND_FLAG: sendFlag + "", //1送审 0未送审
          },
          CONVERT_ORDER:{
            HANDLE_ORG_ID:SelRows.handleOrgId+"",//发起地HANDLE_ORG_ID,参照后台代码specialConvertOrder()取值
            CUST_ORDER_ID:	SelRows.custOrderId+"",//订单编号,参照后台代码specialConvertOrder()取值
            CUST_SO_NUMBER:	SelRows.custSoNumber + "",//流水号
            REGION_TYPE: this.user.regionType,//区域类型 参照 orderOper.js orderDeal 取值
            SUB_CODE:	paramType + "",//按钮操作类型 （1:操作 2：处理 3：输出）
            DEAL_CODE: funcCode + "",//处理编码
            ORG_ID:	this.user.orgId + "",//部门ID
            STAFF_ID:	this.user.staffId + "",//工号ID
            BATCH_NBR: SelRows.batchNbr + "",//参照后台代码specialConvertOrder()取值
            CUST_ID: SelRows.custId + "",
          }
        },
      ];
      //调用规则平台
      // const rescode = await OrderService.rulePlatfromCheckNew(ruleParam);
      await this.callRule(ruleParam);

      if (this.callRuleRtnCode == 2) {
        return;
      }

      if (paramType == "OPER") {

        if (funcCode == "deleteOrder") {
          var batchNbr = SelRows.batchNbr;
          if (batchNbr != "0") {
            var qryProdMap = {
              batchNbr: SelRows.batchNbr,
              custOrderId: SelRows.custOrderId,
            };
            var data = await CustOrderService.qryProdOfferNameReqType(
              qryProdMap
            );

            var resData = data.meta;
            var includeProdOfferIds =
              "10010096|11027575|10010034|10010081|" +
              "10010082|10010036|10010083|10010035";
            for (var i = 0; i < resData.length; i++) {
              var prod_offer_id = resData[i]["PROD_OFFER_ID"];
              if (
                includeProdOfferIds.indexOf(prod_offer_id) > -1 &&
                resData[0]["HANDLE_STATE_CD"] == "50030002"
              ) {
                this.$message({
                  type: "warn",
                  message: "IDC产品只有需求单送审核前能删除订单信息！",
                });
                return;
              }
            }
          }

          var reqMap = {
            custOrderId: SelRows.custOrderId,
            custSoNumber: SelRows.custSoNumber,
            batchNbr: SelRows.batchNbr,
            modReason: "删除订单",
            staffId: this.user.staffId + "",
            custId: SelRows.custId,
          };

          this.isContent.ODKInfo.reqMap = reqMap;
          this.isContent.ODKInfo.deleteType = "deleteCustOrder";
          this.isContent.content = "DeletePage";
          this.pendItemVisible = true;
          //上传附件wyl
        } else if (funcCode == "uploadFile") {
          this.isContent.ODKInfo.sysource = "1";
          this.pendItemVisible = true;
        }else if(funcCode == "uploadElectronicArchives") {
          // 上传电子文档
          this.isContent.ODKInfo.level = "order";
          this.isContent.width = "90%";
          this.isContent.top = "5vh";
          this.pendItemVisible = true;
        }
      } else if (paramType == "DEAL") {
        if (funcCode == "GM_CONVERT_ORDER") {
          //直接转订单(公免工程)
          this.convertOrder(SelRows);
        } else {
          //暂全部调用一个一个方法
          this.convertOrder(SelRows);
        }

        //  this.pendItemVisible = true;
      } else if (paramType == "EXPORT") {
        console.log(funcCode)
        if (funcCode == "outputServiceNotice") {
          this.outputNoticeExcel(SelRows);
        }
      }
    },

    //输出订单列表
    async exportExcelOrderList(paramData) {
      let param = {
        templateType:104,
        offerList: paramData
      };

      const res = await CustOrderService.exportExcelOfferList(param);
      const blob = new Blob([res]);
      let fileName = "订单列表.xls";
      if ("download" in document.createElement("a")) {
        const elink = document.createElement("a");
        elink.download = fileName;
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href);
        document.body.removeChild(elink);
      } else {
        navigator.msSaveBlob(blob, fileName);
      }
    },

    // 转订单
    async convertOrder(SelRows) {

      //直接转订单前置校验
      let res = await this.checkTeshuConvertOrder(SelRows);
      if(!res){
        return;
      }

      let userId = this.user.staffId,
        { orderAuditId, custId, custSoNumber, custOrderId } = SelRows,
        allParams = {
          userId,
          custOrderId,
          custSoNumber,
          orderAuditId,
          custId,
          ...{ paramType: "ORDER" },
          ...{ taskId: "TACHE00080002" },
          ...{ isDirect: "true" },
        };

      // 当批量多条的时候，orderItemSeqs用逗号分隔，现在暂时只传一个
      const result = await CustOrderService.handelConvertOrder(allParams);

      try {
        if (result.meta.resultCode == 0) {
          this.$message({
            type: "success",
            message: "转订单成功!",
          });
          this.qryPendingOrderList({ ...this.conditions });
        } else {
          this.$message({
            showClose: true,
            message: result.meta.resultMsg,
            type: "error",
          });
        }
      } catch {
        this.$message({
          showClose: true,
          message: "code:" + result.code + "  msg:" + result.msg,
          type: "error",
        });
      }
    },
    async outputNoticeExcel() {
      let param = {
        custOrderId: this.isContent.CTOInfo[0].custOrderId,
        offerId: "10010021",
        userId: this.user.staffId + "",
        custId: this.isContent.CTOInfo[0].custId,
        templateType: "2001",
      };
      const res = await CustOrderService.outputNoticeExcel(param);
      const blob = new Blob([res]);
      let fileName = "业务通知单.xls";
      if ("download" in document.createElement("a")) {
        const elink = document.createElement("a");
        elink.download = fileName;
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href);
        document.body.removeChild(elink);
      } else {
        navigator.msSaveBlob(blob, fileName);
      }
    },
    /**
     * 验证特殊转订单
     *  规则1:如果是SDH产品 选择IPTV属性是 需要增加集团批复文件上次功能
     * @param custOrderId
     * @returns {Boolean}
     */
    async checkTeshuConvertOrder(SelRows) {

      //返回值
      var flag = true;
      //默认校验通过
      //todo 先判断是否是集团
      let regionType = this.user.regionType;


      // var orderAuditId = SelRows.orderAuditId;
      // var custId = SelRows.custId;
      var custOrderId = SelRows.custOrderId;
      // var orderStage = this.orderStage;
      // var stage = this.stage;

      // var condition = {
      //   orderAuditId,
      //   custId,
      //   custOrderId,
      //   orderStage: orderStage,
      //   stage: stage,
      //   orgId: this.user.orgId,
      //   staffId: this.user.staffId,
      //   systemUserId: this.user.acctId,
      //   pageInfo: { pageIndex: 1, pageSize: 10 },
      // };

      // //查询消费品信息
      // let result = await CustOrderService.qryPendingOrderItemList(condition);
      // var offerOrderItems = [];
      // if (result.code == 200) {
      //   offerOrderItems = result.meta.offerOrderItems;
      //
      // }

      //调用通用sql查询offerIds  2021071402
      // SELECT OI.ORDER_ITEM_ID, PPOI.OFFER_ID, PO.OFFER_NAME FROM ORDER_ITEM OI, ORD_OFFER_INST PPOI, OFFER PO WHERE OI.ORDER_ITEM_ID = PPOI.ORDER_ITEM_ID AND PPOI.OFFER_ID = PO.OFFER_ID AND OI.CUST_ORDER_ID = 1 AND OI.ORDER_ITEM_CD = '1200' AND OI.MAIN_ORDER_ITEM_FLAG = '1' AND OI.STATUS_CD NOT IN ('101398', '401397', '401398');
      let params = {
        interFaceType: "ORDER",
        sqlId: "2021071402",
        paramStr: "custOrderId:"+custOrderId
      };
      const result = await OrderService.executeSql(params);
      let offerList = result.meta.resList.executeSqlResps;
      var reqMap = {
        custSoNumber: SelRows.custSoNumber,
      };
      var serviceOfferResult = await CustOrderService.getServiceOfferId(reqMap);

      var serviceOfferId = serviceOfferResult.meta;

      // 带宽型产品 SDH,MSTP,DDN,FR,ATM产品 差异化服务单在转定单时系统要求上传附件后才可以进行转定单处理
      var dkCount = 0;
      if (offerList != null) {
        for (var jj = 0; jj < offerList.length - 1; jj++) {
          // var prodOfferId = offerOrderItems[jj]["prodOfferId"];
          var prodOfferId = offerList[jj]["OFFER_ID"];
          var serviceOfferId = SelRows.serviceOfferId;
          if (
            "10010064" == prodOfferId ||
            "10010066" == prodOfferId ||
            "10010019" == prodOfferId ||
            "10010021" == prodOfferId ||
            "10010022" == prodOfferId
          ) {
            //变更和非变不校验
            if (
              serviceOfferId == "4010100000" ||
              serviceOfferId == "4040700001" ||
              serviceOfferId == "4020100000" ||
              serviceOfferId == "5010300036" ||
              serviceOfferId == "5010100001"
            ) {
              dkCount = 1;
              break;
            }
          }
        }
      }
      if (dkCount > 0) {
        /* 客户售后服务等级或者电路维护等级不为普通
        var svcCont = [];
        var data = OdmSvcPub.createReqData("QRY_IS_IPTV_REQ_TYPE", "1.0");
        data.TYPE1 = "1";
        data.CUST_ORDER_ID = custOrderId;
        data.TYPE4 = "4";
        svcCont.push(data);
        var params = OdmSvcPub.createReqObj(svcCont);
        // 查询带宽型产品客户售后服务等级不是普通的销售品订单项
        var jsondkRes = Dic.getOrderItemIds(params);*/
/*
SELECT OI.ORDER_ITEM_SEQ, OI.ORDER_ITEM_ID AS IS_IPTV
  FROM ORDER_ITEM OI, ORDER_ITEM_REL OIR, ORD_PROD_INST PPI
 WHERE OI.ORDER_ITEM_ID = OIR.A_ORDER_ITEM_ID
   AND OI.ORDER_ITEM_CD = '1200'
   AND OIR.Z_ORDER_ITEM_ID = PPI.ORDER_ITEM_ID
   and OI.CUST_ORDER_ID = '103080177'
   and ((SELECT PPIA.ATTR_VALUE
           FROM ORD_PROD_INST_ATTR PPIA
          WHERE PPIA.PROD_INST_ID = PPI.PROD_INST_ID
            AND ATTR_CD = 'LEVEL_CUST') != '80050035004' OR
       (SELECT PPIA.ATTR_VALUE
           FROM ORD_PROD_INST_ATTR PPIA
          WHERE PPIA.PROD_INST_ID = PPI.PROD_INST_ID
            AND ATTR_CD = 'INTER_LEVEL_MIAN') != '80050036007')
*/
        let params = {
        interFaceType: "ORDER",
        sqlId: "2021071601",
        paramStr: "custOrderId:"+custOrderId
        };
        let commonSqlRtnList;
        const result = await OrderService.executeSql(params);
        if (result.code == 200) {
          this.bufferLoading = false;
          commonSqlRtnList = result.meta.resList.executeSqlResps;
        } else {
          this.bufferLoading = false;

        }

        if (commonSqlRtnList.length > 0) {
          // 2.判断是否上传了文件
          var fileTypeCd =
            "98410001,98410002,98410003,98410004,98410005,98410006";
          // var jsondkRes1 = Dic.isUploadFilesByOrderId(custOrderId, fileTypeCd);
        let params = {
        interFaceType: "ORDER",
        sqlId: "2021071603",
        paramStr: "custOrderId:"+custOrderId+";fileTypeCd:"+fileTypeCd
        };
        let commonSqlRtnList;
        const result = await OrderService.executeSql(params);
        if (result.code == 200) {
          this.bufferLoading = false;
          commonSqlRtnList = result.meta.resList.executeSqlResps;
        } else {
          this.bufferLoading = false;

        }

          // 集团下单的国内电路，非A端业务
          // 1.当 “客户售后服务等级” 为VIP-SL1、VIP-SL2、VIP-SL3
          // 2.“电路维护等级”为 AAA、AA、A 、I级、II级、III级时,  变更单 不需要校验是否上传了差异化服务单。  lvxx
          var count = 1; //默认大于0

          // var isJT = ruleTrig.call(
          //   "isJTInternalBg",
          //   "custOrderId#" + custOrderId
          // );

        params = {
        interFaceType: "ORDER",
        sqlId: "2021071604",
        paramStr: "custOrderId:"+custOrderId
        };
        commonSqlRtnList;
        result = await OrderService.executeSql(params);
        if (result.code == 200) {
          this.bufferLoading = false;
          commonSqlRtnList = result.meta.resList.executeSqlResps;
        } else {
          this.bufferLoading = false;

        }

          // 判断是否是集团发起的国内
          if (commonSqlRtnList > 0 ) {
            //当全部符合 才进行详细判断
            // count = ruleTrig.call(
            //   "isNeedUpdateFile",
            //   "custOrderId#" + custOrderId
            // );
            //判断此流水是否符合以上标准 如果存在不符合的就需要 上次附件
            let params = {
            interFaceType: "ORDER",
            sqlId: "2021071605",
            paramStr: "custOrderId:"+custOrderId
            };
            let commonSqlRtnList;
            const result = await OrderService.executeSql(params);
            if (result.code == 200) {
              this.bufferLoading = false;
              commonSqlRtnList = result.meta.resList.executeSqlResps;
            } else {
              this.bufferLoading = false;

            }

          }
          if (commonSqlRtnList > 0) {
            let tipMsg = "流水" + SelRows.custSoNumber + "下某条电路是差异化服务单,需要上传文件!";
            await this.$confirm(tipMsg, "提示", {
              confirmButtonText: "确定",
              type: "warning",
            })
              .then(() => {})
              .catch(() => {});

            flag = false;
            return false;
          }
        }
      }

      // SDH选择IPTV 需要增加集团批复文件
      var sdhCount = 0;
      if (offerList!=null) {
        for (var kk = 0; kk < offerList.length - 1; kk++) {
          if ("10010022" == offerList[kk].OFFER_ID) {
            sdhCount = 1;
            break;
          }
        }
      }
      if (sdhCount > 0) {
        /*
        var svcCont = [];
        var data = OdmSvcPub.createReqData("QRY_IS_IPTV_REQ_TYPE", "1.0");
        data.TYPE1 = "1";
        data.CUST_ORDER_ID = custOrderId;
        data.TYPE3 = "3";
        svcCont.push(data);
        var params = OdmSvcPub.createReqObj(svcCont);
        // 查询SDH产品是IPTV属性的销售品订单项
        var jsonRes = Dic.getOrderItemIds(params); */

        let params = {
        interFaceType: "ORDER",
        sqlId: "2021071601",
        paramStr: "custOrderId:"+custOrderId
        };
        const result = await OrderService.executeSql(params);
        let iptvOrderItems = result.meta.resList.executeSqlResps;

        if (iptvOrderItems.length > 0) {
          // 判断是否上传了集团批复文件
          var fileTypeCd = "98410003";
          // var jsondkRes1 = Dic.isUploadFilesByOrderId(custOrderId, fileTypeCd);
          let params = {
          interFaceType: "ORDER",
          sqlId: "2021071603",
          paramStr: "custOrderId:"+custOrderId+";fileTypeCd:"+fileTypeCd
          };
          const result = await OrderService.executeSql(params);
          //对应上传文件
          let upfileList = result.meta.resList.executeSqlResps;

          if (upfileList.length==0) {
            let tipMsg = "流水" + SelRows.custSoNumber + "下某条SDH电路选择IPTV,需要提交集团批复文件!";
            await this.$confirm(tipMsg, "提示", {
              confirmButtonText: "确定",
              type: "warning",
            })
              .then(() => {})
              .catch(() => {});

            flag = false;
            return false;
          }
        }
      }
      return flag;
    },


    async dealShowEvent(type) {

      if (type == 1) {
        var res1 = await CustOrderService.queryOrderManager({
          funcType: 1,
          funcKind: 0,
          userId: "",
        });
        var res = res1.meta;
        this.operateWithData = this.dealTaskHand(res, this.selectedItems, type);
      } else if (type == 2) {
        var res1 = await CustOrderService.queryOrderManager({
          funcType: 1,
          funcKind: 1,
          userId: "",
        });
        var res = res1.meta;

        this.dealWithData = this.dealTaskHand(res, this.selectedItems, type);

      } else if (type == 3) {
        var res1 = await CustOrderService.queryOrderManager({
          funcType: 1,
          funcKind: 2,
          userId: "",
        });
        var res = res1.meta;
        this.outputWithData = this.dealTaskHand(res, this.selectedItems, type);
      }
    },
    // 待处理list处理
    dealTaskHand(list, CTOInfo, type) {
      let content = [];
      list.map((item) => {
        if (type == 1) {
          item.paramType = "OPER";
        } else if (type == 2) {
          item.paramType = "DEAL";
        } else if (type == 3) {
          item.paramType = "EXPORT";
        }

        let width = "";
        let top = "";
        if (
          item.taskUrl == "TariffVerification" ||
          item.taskUrl == "ResourceSurvey" ||
          item.taskUrl == "DoCommonTask"
        ) {
          width = "98%";
          top = "3vh";
        } else {
          width = "50%";
          top = "15vh";
        }
        content.push({
          title: item.ALIAS_NAME,
          ODKInfo: item,
          CTOInfo: CTOInfo,
          content: item.WEB_PAGE,
          width: width,
          top: top,
        });
      });
      return content;
    },
    /**
     * 点击查询
     */
    eventDoSearch() {

      this.qryPendingOrderList({ ...this.conditions });
    },
    /**
     * 警告单选按钮改变时
     */
    warnChange() {

      this.qryPendingOrderList({ ...this.conditions });
    },
    /**
     * 查询类型改变时
     */
    qryTypeChange() {
      this.$store.commit("orders/SET_QRYVALUE", "");
    },
  },
};
</script>

<style lang="scss" scoped>
.u-point {
  //   display: inline-block;
  width: 4px;
  height: 4px;
  background: #666;
  border-radius: 50%;
  float: left;
  margin-top: 0.13rem;
  margin-right: 0.1rem;
}
.dev {
  color: #666;
  font-size: $fontSize_base;
  text-align: right;
  .el-radio {
    top: 0.1rem;
  }
  ::v-deep .el-input__inner {
    //width: auto;
    height: 0.34rem;
    line-height: 0.34rem;
  }
  ::v-deep .el-input__icon {
    line-height: 0.34rem;
  }
  ::v-deep .ne-tg-ipt {
    .el-input__icon {
      line-height: 0.24rem;
    }
    .el-date-editor {
      width: auto;
    }
  }
  .el-form-item {
    margin-bottom: 4px;
  }
  .ne-operation {
    margin-left: -0.5px;
  }
  .ne-pending {
    .ne-pending-items {
      height: auto;
      flex-wrap: wrap;
      max-width: 2.5rem;
      li {
        padding: 0.05rem;
        a {
          color: $textColor1;
          padding-left: 0.1rem;
          position: relative;
          &:hover {
            text-decoration: none;
            color: $blue;
            &:before {
              background-color: $blue;
            }
          }
          &:before {
            display: inline-block;
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            margin: auto;
            width: 0.05rem;
            height: 0.05rem;
            border-radius: 50%;
            background-color: $textColor1;
          }
        }
      }
    }
  }
}
.ne-pending-items {
  flex-wrap: wrap;
  max-width: 2.5rem;
  li {
    padding: 0.05rem;
    a {
      color: $textColor1;
      padding-left: 0.1rem;
      position: relative;
      &:hover {
        text-decoration: none;
        color: $blue;
        &:before {
          background-color: $blue;
        }
      }
      &:before {
        display: inline-block;
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        margin: auto;
        width: 0.05rem;
        height: 0.05rem;
        border-radius: 50%;
        background-color: $textColor1;
      }
    }
  }
}
</style>
